package com.freesky.common.utils;

import cn.hutool.core.util.StrUtil;
import org.hashids.Hashids;

import java.security.InvalidAlgorithmParameterException;

public class HashIdUtils {

    private static final Hashids HASHIDS = new Hashids("VkQomJ7hY8XkGahO", 8);

    public static String encode(Long source) {
        return HASHIDS.encode(source);
    }

    public static Long decode(String source) {
        return HASHIDS.decode(source)[0];
    }


    public static void main(String args[]) throws Exception, InvalidAlgorithmParameterException {
        System.out.println(HashIdUtils.encode(1034L));
        System.out.println(HashIdUtils.encode(1038L));
        System.out.println(HashIdUtils.decode("n9qmm9qY"));

        String format = "LOTTERY:{}:PRIZE";
        System.out.println(StrUtil.format(format,"1002"));

    }
}
